package com.sam.enumeration;

/**
 * 枚举策略模式【改进】
 * @author Administrator
 *
 */
public enum PayrollDay2 {
	MONDAY(PayType.WEEKDAY), TUESDAY(PayType.WEEKDAY), WEDENSDAY(
			PayType.WEEKDAY), THURSDAY(PayType.WEEKDAY), FRIDAY(PayType.WEEKDAY), SATURADY(
			PayType.WEEKEND), SUNDAY(PayType.WEEKEND);

	private final PayType payType;

	private PayrollDay2(PayType payType) {
		this.payType = payType;
	}

	double pay(double hoursWorked, double payRate) {
		return payType.pay(hoursWorked, payRate);
	}

	private enum PayType {

		WEEKDAY {
			@Override
			double overtimePay(double hrs, double payRate) {

				return hrs <= HOURS_PER_SHIFT ? 0 : (hrs - HOURS_PER_SHIFT)
						* payRate / 2;
			}
		},
		WEEKEND {
			@Override
			double overtimePay(double hrs, double payRate) {

				return hrs * payRate / 2;
			}
		};
		private static final int HOURS_PER_SHIFT = 8;

		abstract double overtimePay(double hrs, double payRate);

		double pay(double hoursWorked, double payRate) {

			double basePay = hoursWorked * payRate;

			return basePay + overtimePay(hoursWorked, payRate);

		}

	}

	public static void main(String args[]) {

		System.out.println(PayrollDay2.MONDAY.pay(8, 100));
		System.out.println(PayrollDay2.SUNDAY.pay(8, 100));
	}

}
